package com.hzit.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 类名：
 * 作者：WF
 * 功能：用户登录
 */
@Component
public class UserLoginInterceptor implements HandlerInterceptor {
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		//1. 得到当前的session对象
		HttpSession session = request.getSession();
		Object username = session.getAttribute("username");
		if(username == null){
			System.out.println("UserLoginInterceptor--->preHandle()");
			response.sendRedirect("/login.jsp");
			return false;
		}

		return true;
	}
}
